﻿<metro:Window x:Class="MongoBackupManager.MainWindow"
              xmlns:local="clr-namespace:MongoBackupManager"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              Icon="Images/app-small.png" 
              Title="{Binding AppTitle, Mode=OneTime}" 
              Height="600" 
              Width="800"
              xmlns:metro="http://schemas.codeplex.com/elysium"
              xmlns:params="http://schemas.codeplex.com/elysium/params"
              params:Manager.Theme="Dark"
              params:Manager.AccentBrush="{x:Static metro:AccentBrushes.Blue}"
              params:Manager.ContrastBrush="White"
              params:Window.MinimizeButtonToolTip="Minimize"
              params:Window.MaximizeButtonToolTip="Maximize"
              params:Window.RestoreButtonToolTip="Restore down"
              params:Window.CloseButtonToolTip="Close">
    <Grid Background="{StaticResource MainBackground}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="4*" />
            <ColumnDefinition Width="3*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="80" />
            <RowDefinition Height="1*" />
            <RowDefinition Height="2*"/>
        </Grid.RowDefinitions>
        <GridSplitter HorizontalAlignment="Left" Grid.Column="1" Grid.RowSpan="3" Grid.Row="0" 
                      VerticalAlignment="Stretch" Width="5"/>

        <Grid x:Name="grdButtons"  DataContext="{Binding Settings}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Button Grid.Row="0" Grid.Column="0" Content="Backup" Margin="2" Command="{Binding BackupCommand}" />
        </Grid>

        <DataGrid x:Name="grdFiles" Grid.Row="1" Background="Transparent" Margin="2" 
                  AutoGenerateColumns="False" CanUserAddRows="False" CanUserResizeRows="False" CanUserResizeColumns="False" IsReadOnly="True"
                  DataContext="{Binding Settings}" 
                  ItemsSource="{Binding BackupFiles, Mode=OneWay}"
                  SelectedItem="{Binding SelectedFile, Mode=TwoWay}">
            <DataGrid.Columns>
                <DataGridTextColumn Header="Created" SortDirection="Descending" CanUserSort="True" 
                                    SortMemberPath="{Binding CreatedDate}" Binding="{Binding CreatedDateStr}" />
                <DataGridTextColumn Header="File Name" SortDirection="Descending" CanUserSort="True" Width="1*"
                                    SortMemberPath="{Binding Name}" Binding="{Binding Name}" />
            </DataGrid.Columns>
            <DataGrid.ContextMenu>
                <ContextMenu IsEnabled="{Binding IsFileSelected}">
                    <MenuItem Command="{Binding RestoreCommand}" Header="Restore" />
                    <MenuItem Command="{Binding DeleteCommand}"  Header="Delete" />
                </ContextMenu>
            </DataGrid.ContextMenu>
        </DataGrid>

        <TextBox x:Name="txtLog" Grid.Row="2" Text="{Binding Log}" 
                 Margin="2" FontFamily="Lucida Console" 
                 TextWrapping="Wrap" Background="Transparent" Foreground="GreenYellow" IsReadOnly="True" 
                 VerticalScrollBarVisibility="Visible" FontSize="14" />

        <ScrollViewer x:Name="scrollSettings" Grid.Column="1" Grid.RowSpan="3" 
                      HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Visible">
            <Grid DataContext="{Binding Settings}" Margin="10,0,5,0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0" Text="Settings" />

                <TextBlock Grid.Row="1" Text="Time" />
                <TextBox Grid.Row="2" Text="{Binding CurrentTimeStr, Mode=OneWay}" IsReadOnly="True" />

                <TextBlock Grid.Row="3" Text="Mongodump Path"/>
                <TextBox Grid.Row="4" Text="{Binding MongodumpPath, Mode=TwoWay}"/>

                <TextBlock Grid.Row="5" Text="Host" />
                <TextBox Grid.Row="6" Text="{Binding Host, Mode=TwoWay}"/>

                <TextBlock Grid.Row="7" Text="Port" />
                <TextBox Grid.Row="8" Text="{Binding Port, Mode=TwoWay}"/>

                <TextBlock Grid.Row="9" Text="Username"/>
                <TextBox Grid.Row="10" Text="{Binding DbUserName, Mode=TwoWay}"/>

                <TextBlock Grid.Row="11" Text="Password"/>
                <PasswordBox Grid.Row="12"
                             local:PasswordBoxAssistant.BindPassword="True" 
                             local:PasswordBoxAssistant.BoundPassword="{Binding DbPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                <TextBlock Grid.Row="13" Text="Backup Path"/>
                <TextBox Grid.Row="14" Text="{Binding BackupPath, Mode=TwoWay}"/>

                <TextBlock Grid.Row="13" Text="Backup Path"/>
                <TextBox Grid.Row="14" Text="{Binding BackupPath, Mode=TwoWay}"/>

                <Button Grid.Row="15" Margin="0,10" Content="Test Connection" Command="{Binding TestConnectionCommand}" />

                <TextBlock Grid.Row="16" Text="Include Database(s) to Backup"/>
                <DataGrid Grid.Row="17"
                    AutoGenerateColumns="False" CanUserAddRows="False" CanUserResizeRows="False" CanUserResizeColumns="False" IsReadOnly="True"
                    ItemsSource="{Binding DataBases, Mode=OneWay}">
                    <DataGrid.Columns>
                        <DataGridCheckBoxColumn Header="Select" SortDirection="Descending" CanUserSort="False" 
                                            Binding="{Binding IsSelected,Mode=TwoWay, FallbackValue=True}" />
                        <!--<DataGridTextColumn Header="Created" SortDirection="Descending" CanUserSort="True" 
                                    SortMemberPath="{Binding CreatedDate}" Binding="{Binding CreatedDateStr}" />-->
                        <DataGridTextColumn Header="File Name" SortDirection="Descending" CanUserSort="True" Width="1*"
                                    SortMemberPath="{Binding Name}" Binding="{Binding Name}" />
                    </DataGrid.Columns>
                </DataGrid>

                <TextBox Grid.Row="14" Text="{Binding BackupPath, Mode=TwoWay}"/>

                <CheckBox Grid.Row="20" IsEnabled="False"
                          IsChecked="{Binding IsCompressOn, Mode=TwoWay, FallbackValue=True}">
                    <CheckBox.Content>
                        <TextBlock TextWrapping="Wrap">
                            Compress after backup (If selected backup folder will be compressed in a zip file [host]_[date].zip')
                        </TextBlock>
                    </CheckBox.Content>
                </CheckBox>
                
                <CheckBox Grid.Row="21" IsChecked="{Binding IsPeriodicBackupOn, Mode=TwoWay,FallbackValue=True}">
                    <CheckBox.Content>
                        <TextBlock TextWrapping="Wrap">
                            Daily backup (If selected a backup every day at 00:00 will be created)
                        </TextBlock>
                    </CheckBox.Content>
                </CheckBox>
                
            </Grid>
        </ScrollViewer>
    </Grid>
</metro:Window>
